/******************************************************************************
 * Copyright (C) 2024 EternalChip, Inc.(Gmbh) or its affiliates.
 * 
 * All Rights Reserved.
 * 
 * @file bsp_led_driver.h
 * 
 * @par dependencies 
 * - stdio.h
 * - stdint.h
 * 
 * @author rnz | zjut
 * 
 * @brief Provide the  APIs of LEDs and corresponding opetions.
 * 
 * Processing flow:
 * 
 * call directly.
 * 
 * @version V1.0 2025-5-7
 *
 * @note 1 tab == 4 spaces!
 * 
 *****************************************************************************/
#ifndef _BSP_LED_DRIVER_H_
#define _BSP_LED_DRIVER_H_

//******************************** Includes *********************************//
#include <stdio.h>
#include <stdint.h>

//******************************** Includes *********************************//

//******************************** Defines **********************************//
#define INITED                   1  /*LED is inited*/
#define NOT_INITED               0  /*LED is not inited*/

#define DEBUG                       /*Enable DEBUG*/
#define DEBUG_OUT(X)   printf(X)     /*Print debug info*/
typedef enum
{
    PROOPRTION_1_3           = 0,
    PROOPRTION_1_2           = 1,
    PROOPRTION_1_1           = 2,
    PROOPRTION_x_x           = 0xFF,
}proportion_t;

typedef enum
{
    LED_OK                   = 0, 
    LED_ERROR                = 1,
    LED_ERRORTIMEOUT         = 2,
    LED_ERRORRESOURCE        = 3,
    LED_ERRORPARAMETER       = 4,
    LED_ERRORNOMEMORY        = 5,
    LED_ERRORISR             = 6,
    LED_RESERVED             = 0xFF,
   
}led_status_t;

typedef struct       
{
    led_status_t (*pf_led_on)                  (void);
    led_status_t (*pf_led_off)                 (void);
}led_operations_t;

typedef struct 
{
    led_status_t (*pf_get_time_ms)  (uint32_t * const);
}time_base_ms_t;


typedef struct 
{
    led_status_t (*pf_os_delay_ms)  (const uint32_t *);
}os_delay_t;

typedef led_status_t (*pf_led_control_t)(
                                         uint32_t ,            //Cycle_time[ms]
                                         uint32_t ,            //blink_times[times]
                                         proportion_t        //proportion_on_off
                                                    );

typedef struct 
{
    /*********Tarhet of Internal Status****/
    uint8_t                            is_inited;
    /*********Tarhet of Features***********/
    /*The time of light on                */
    uint32_t                          on_time_ms;
    /*The whole time of blink             */
    uint32_t                       cycle_time_ms;      
    /*The times of blink                  */
    uint32_t                         blink_times; 
    /*The relationship of light on and off*/
    proportion_t               proportion_on_off;
    /********Tarhet of IOs needed**********/
    /* The interface from Core layer      */
    led_operations_t            *p_led_opes_inst;
    time_base_ms_t               *p_time_base_ms;
    /* The interface from Os layer        */
    os_delay_t                  *p_os_time_delay;
    /********Tarhet of IOs APIs************/
    pf_led_control_t           pf_led_countroler;

}bsp_led_driver_t;

//******************************** Defines **********************************//

//******************************** Declaring ********************************//
/**
 * @brief Instantiates the target of bsp_led_driver_t.
 * 
 * Steps:
 *  1. Adds the Core interfaces into bsp_led_driver instance.
 *  2. Adds the Os interfaces into bsp_led_driver instance.
 *  3. Adds the timebase interfaces into bsp_led_driver instance.
 *  
 * @param[in] self        : Pointer to the target of handler.
 * @param[in] led_ops    : Pointer to the os_delay_interface.
 * @param[in] os_delay    : Pointer to the os_queue_interface.
 * @param[in] time_base : Pointer to the os_critical_interface.
 * 
 * @return led_status_t : Status of running.
 * 
 * */
led_status_t led_driver_inst (
                                bsp_led_driver_t        *  const       self,
                                const led_operations_t  *  const    led_ops,
                                const os_delay_t        *  const   os_delay,
                                const time_base_ms_t    *  const  time_base
);

//******************************** Declaring ********************************//




#endif //END of _BSP_LED_DRIVER_H_
